package cn.tedu.dao.persist.repositoy.impl;

import cn.tedu.dao.persist.mapper.UserDetailsMapper;
import cn.tedu.dao.persist.repositoy.IUserDetailsRepository;
import cn.tedu.pojo.entity.UserDetails;
import cn.tedu.pojo.vo.UserDetailsVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class UserDetailsRepositoryImpl implements IUserDetailsRepository {

    @Autowired
    private UserDetailsMapper userDetailsMapper;

    @Override
    public int insert(UserDetails userDetails) {
        return userDetailsMapper.insert(userDetails);
    }

    @Override
    public UserDetailsVO getStandard(Long userId) {
        return userDetailsMapper.getStandard(userId);
    }

    @Override
    public int updateById(UserDetails userDetails) {
        return userDetailsMapper.updateById(userDetails);
    }

    @Override
    public int countByPhoneAndNotId(String phone, Long userId) {
        QueryWrapper<UserDetails> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phoneNumber", phone);
        queryWrapper.ne("userId", userId);
        return userDetailsMapper.selectCount(queryWrapper);
    }

    @Override
    public int countByEmailAndNotId(String email, Long userId) {
        QueryWrapper<UserDetails> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("email", email);
        queryWrapper.ne("userId", userId);
        return userDetailsMapper.selectCount(queryWrapper);
    }
}
